﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="productparam.aspx.cs" Inherits="UI.system.page.product.productparam" %>
<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<%@ Import Namespace="Common" %>

    <style>
        td img{width:28px; height:28px; float:left; object-fit:cover}
        #iframe .right{width:100%; height:auto; border:1px solid #e2e2e2; float:left; border-bottom:0px;}
        .right .title{width:100%; height:38px; line-height:38px; float:left; padding-left:10px; background-color:#f2f2f2; border-bottom:1px solid #e2e2e2;}
        .right .title .l{width:100px; float:left;}
        .right .title .m{width:320px; float:left;padding-left:10px; border-left:1px solid #e2e2e2;}
        
        .right .title .r{width:auto; float:right;}
        .right .title .r .sort{width:80px; height:38px; float:left; padding-left:10px; padding-top:0px; margin-right:10px; border-left:1px solid #e2e2e2;}
        .right .title .r .delete{width:155px; height:38px; float:left; padding-left:10px; padding-top:0px; border-left:1px solid #e2e2e2;}
        .right .lines{width:100%; height:38px; line-height:38px; min-height:38px; float:left; padding-left:10px; border-bottom:1px solid #e2e2e2;}
        .right .lines .l{width:100px; float:left;}
        .right .lines .m{width:320px; float:left; height:38px; padding-top:5px; padding-left:10px; border-left:1px solid #e2e2e2;}
        .right .lines .m input{width:302px !important;}
        .right .lines .r{width:auto; float:right;}
        .right .lines .r .sort{width:80px; height:38px; float:left; padding-left:10px; padding-top:5px; margin-right:10px; border-left:1px solid #e2e2e2;}
        .right .lines .r .delete{width:155px; height:38px; float:left; padding-left:10px; padding-top:0px; border-left:1px solid #e2e2e2;}
    </style>
    <form id="form1" runat="server" style="margin-bottom:50px; padding:10px;">
    <div class="layui-searchbar">
        <div class="left"><div class="layui-input-inline" style="margin-right:5px;"><a href="javascript:void(0)" class="layui-btn layui-btn-small" onclick="Save(this,0)">新增参数组</a></div><div class="layui-input-inline"><a href="javascript:void(0)" class="layui-btn layui-btn-small layui-btn-normal" onclick="Save(this,0)">新增参数</a></div></div>
        <div class="right"><a id="search" class="layui-btn layui-btn-small layui-btn-normal" onclick="Sure()">确定</a></div>
    </div>
    <div id="iframe">
        <div class="right">
            <div class="title"><div class="l">参数名</div><div class="m">参数值</div><div class="r"><div class="sort">顺序</div><div class="delete">操作</div></div></div>
            <div id="layer-table"></div>
        </div>
    </div>
    <script id="data-table" type="text/html">
      {{#  layui.each(d, function(index, d){ }}
        {{# if(d.Type==1){ }}
        <div class="lines" style="background:#ecfbef;"><div class="l">{{d.Name}}</div><div class="m"></div><div class="r"><div class="sort"><input class="layui-input tdtext" value="{{d.Sort}}" onblur="ReSort(this,{{d.ID}},'productparam')" /></div><div class="delete"><a href="javascript:void(0)" class="layui-btn layui-btn-mini" style="background-color:#1AA094" onclick="Save(this,{{d.ID}})">编辑</a>&nbsp;<a href="javascript:void(0)" class="layui-btn layui-btn-mini" style="background-color:#FF6838" onclick="Delete(this,{{d.ID}})">删除</a>&nbsp;<a class="layui-btn layui-btn-mini layui-btn-normal" onclick="Save(this,0)" parentid="{{d.ID}}">添加</a></div></div></div>
        {{# $.each(d.ChildList,function(i,d){ }}
        <div class="lines"><div class="l">&nbsp;&nbsp;&nbsp;&nbsp;{{d.Name}}</div><div class="m"><input class="layui-input tdtext" value="{{d.Value}}" onblur="ReName(this,{{d.ID}})" /></div><div class="r"><div class="sort"><input class="layui-input tdtext" value="{{d.Sort}}" onblur="ReSort(this,{{d.ID}},'productparam')" /></div><div class="delete"><a href="javascript:void(0)" class="layui-btn layui-btn-mini" style="background-color:#1AA094" onclick="Save(this,{{d.ID}})">编辑</a>&nbsp;<a href="javascript:void(0)" class="layui-btn layui-btn-mini" style="background-color:#FF6838" onclick="Delete(this,{{d.ID}})">删除</a>&nbsp;</div></div></div>
        {{# }); }}
        {{# } }}
        {{# if(d.Type==2 && d.ParentID==0){ }}
        <div class="lines"><div class="l">{{d.Name}}</div><div class="m"><input class="layui-input tdtext" value="{{d.Value}}" onblur="ReName(this,{{d.ID}})" /></div><div class="r"><div class="sort"><input class="layui-input tdtext" value="{{d.Sort}}" onblur="ReSort(this,{{d.ID}},'productparam')" /></div><div class="delete"><a href="javascript:void(0)" class="layui-btn layui-btn-mini" style="background-color:#1AA094" onclick="Save(this,{{d.ID}})">编辑</a>&nbsp;<a href="javascript:void(0)" class="layui-btn layui-btn-mini" style="background-color:#FF6838" onclick="Delete(this,{{d.ID}})">删除</a>&nbsp;</div></div></div>
        {{# } }}
      {{# }); }}
      </script>
    </form>

    <script>
        layui.use(["form", "table"], function () {
            var $ = layui.jquery, form = layui.form;
            table = layui.table;
            Init_Pager();
        });

        function Init_Pager() {
            var data = {};
            data.act = "Find_ProductParam";
            data.productid = "<%=productid %>";
            data.sign = GetSign(data.act);
            Loading2();
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    Data2(json.data);
                }
                else {
                    LayerBox.Error(json.msg);
                }
            });
        };

        function Save(o, id) {
            var type = 0;
            var parentid = 0;
            if ($(o).html() == "新增参数组") {
                type = 1;
            } else {
                type = 2;
            }
            if ($(o).attr("parentid")) {
                parentid = $(o).attr("parentid");
            } else {
                parentid = 0;
            }
            Ajax.Get("/system/page/product/productparamadd.aspx?id=" + id + "&type=" + type + "&parentid=" + parentid, function (html) {
                var title = id == 0 ? "新增" : "修改";
                var index = LayerBox.Show2(title, html, "400px", "280px", null, function (form) {
                    var data = form;
                    data.act = "Save_ProductParam";
                    data.id = id;
                    data.parentid = parentid;
                    data.type = type;
                    data.productid = "<%=productid %>";
                    data.sign = GetSign(data.act);
                    var loading=LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByIndex(index);
                                LayerBox.Close.ByIndex(loading);
                                if (id == 0) {
                                    Init_Pager();
                                } else {
                                    Init_Pager();
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
        function Delete(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_ProductParam");
            });
        };

        function ReName(o, id) {
            var data = {};
            data.act = "Update_ProductParamName";
            data.id = id;
            data.name = $(o).val();
            data.sign = GetSign(data.act);
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
            });
        };
        function Sure() {
            LayerBox.Close.ByIndex(product_index);
        };

        window.parent.$("#setparam").attr("setparam","1");
</script>